<?php
namespace app\admin\controller;

use app\common\model\UserCollect as UserCollectModel;
use app\common\model\User as UserModel;
use app\common\controller\AdminBase;
use think\Db;
use think\Session;
use think\Model;

class UserCollect extends AdminBase
{
	protected $usercollect_model;
	protected $article_model;
	protected $usedtruck_model;
	protected $user_model;

	protected function _initialize()
	{
		parent::_initialize();
		$this->usercollect_model = new UserCollectModel();
		$this->article_model = model('article');
		$this->usedtruck_model = model('used_truck');
		$this->user_model = new UserModel();

		$article_list = $this->article_model->where('status',1)->column('title','id');
		$usedtruck_list = $this->usedtruck_model->where('status',1)->column('title','id');
		$user_list = $this->user_model->where('status',1)->column('name','id');

		$this->assign('article_list',$article_list);
		$this->assign('usedtruck_list',$usedtruck_list);
		$this->assign('user_list',$user_list);
	}

	public function index($page = 1)
	{
		$usercollect_list = $this->usercollect_model->order('id DESC')->paginate(15,false,['page' => $page]);

		return $this->fetch('index',['usercollect_list'=>$usercollect_list]);
	}

	public function reading($id)
	{
		$usercollect = $this->usercollect_model->find($id);

		return $this->fetch('reading',['usercollect' => $usercollect]);
	}

	public function delete($id = 0, $ids = [])
	{
		$id = $ids ? array_merge($ids) : $id;
		if($id){
			if($this->usercollect_model->destroy($id)){
				return $this->success('删除成功');
			}else{
				return $this->error('删除失败');
			}
		}else{
			return $this->error('请选择需要删除的内容');
		}
	}
}